/**
 *用户行为分析业务实现函数
 */
if (typeof(Constants) != 'object') {
    Constants = {};
    Constants.isYytPlatform = true;
}

function getYytBusiUbalogInfo(ubalogData) {
    var ubalog = {};
    ubalog.uc = Utils.getCookie('usercode');
    ubalog.license = ubalog.uc;
    var userInfo = JSON.parse(JSON.parse(sessionStorage.getItem(ubalog.uc + '_userinfo')).value);
    ubalog.un = userInfo.userName;
    if (!ubalog.billid && typeof(app) != 'undefined') {
        ubalog.billid = app.currentBillId;
    }

    // 按页面取信息
    var path = location.pathname || "";
    var hash = location.hash || "";
    if (path == '/marketing-orderplatform/ui/pages/index.html') { // 订货平台首页
        ubalog.pt = ubalog.pt || '订货平台首页';
    } else if (path == '/marketing-orderplatform/ui/pages/infodetail.html') { // 公告列表
        ubalog.pt = ubalog.pt || '公告列表';
    } else if (path == '/marketing-orderplatform/ui/pages/noticedetail.html') { // 公告详情
        ubalog.pt = ubalog.pt || '公告详情';
        ubalog.billid = ubalog.billid || getUrlParam('pk_messageinfo');
    } else if (path == '/marketing-orderplatform/ui/pages/list.html') { // 品牌展示列表
        ubalog.pt = ubalog.pt || '品牌展示列表';
    } else if (path == '/marketing-orderplatform/ui/pages/detail.html') { // 品牌展示详情
        ubalog.pt = ubalog.pt || '品牌展示详情';
        ubalog.billid = ubalog.billid || getUrlParam('pk_cigarette');
    } else if (path == '/marketing-orderplatform/ui/pages/openinfo.html') { // 信息公开列表
        ubalog.pt = ubalog.pt || '信息公开列表';
    } else if (path == '/marketing-orderplatform/ui/pages/openinfodetail.html') { // 信息公开详情
        ubalog.pt = ubalog.pt || '信息公开详情';
        ubalog.billid = ubalog.billid || getUrlParam('pk_infocollaboration');
    } else if (path == '/marketing-orderplatform/ui/pages/retail.html') { // 零售之窗列表
        ubalog.pt = ubalog.pt || '零售之窗列表';
    } else if (path == '/marketing-orderplatform/ui/pages/retaildetail.html') { // 零售之窗详情
        ubalog.pt = ubalog.pt || '零售之窗详情';
        ubalog.billid = ubalog.billid || getUrlParam('pk_infocollaboration');
    } else if (path == '/marketing-orderplatform/ui/pages/complaints.html' && hash.indexOf("#/list") == 0) { // 咨询投诉列表
        ubalog.pt = ubalog.pt || '咨询投诉列表';
    } else if (path == '/marketing-orderplatform/ui/pages/complaints.html' && hash.indexOf("#/card") == 0) { // 咨询投诉详情
        ubalog.pt = ubalog.pt || '咨询投诉详情';
        ubalog.billid = ubalog.billid || getUrlParamByUrl(hash, 'billId');
    } else if (path == '/marketing-orderplatform/ui/pages/personal.html') { // 个人信息
        ubalog.pt = ubalog.pt || '个人信息';
    } else if (path == '/marketing-orderplatform/ui/pages/questionnaire.html') { // 我的问卷列表
        ubalog.pt = ubalog.pt || '我的问卷';
    }

    //获取省市组织
    var isinitorg = sessionStorage.getItem(ubalog.uc + '_isinitorg');
    var provorg = sessionStorage.getItem(ubalog.uc + '_provorg');
    var cityorg = sessionStorage.getItem(ubalog.uc + '_cityorg');
    if (isinitorg != "true" && (provorg == null || cityorg == null)) {
        sessionStorage.setItem(ubalog.uc + '_isinitorg', true);
        var result = yytUtil.ajax({
            async: false,
            url: '/marketing-orderplatform/MOH4/MOH404/MOH40406/getOrgInfo.json'
        });
        cityorg = result.pk_org
        provorg = result.pk_prov_org;
        if (cityorg != null) {
            sessionStorage.setItem(ubalog.uc + '_cityorg', cityorg);
            sessionStorage.setItem(ubalog.uc + '_provorg', provorg);
        }
    }
    ubalog.cityorg = cityorg;
    ubalog.provorg = provorg;
    ubalog.url = ubalog.url || window.top.document.URL; // url
    ubalog.title = window.top.document.title; // 标题
    ubalog.surl = window.top.document.referrer; // 来源url
    return ubalog;
}


// 获取url参数
function getUrlParam(strParame) {
    return getUrlParamByUrl(location.search, strParame);
};

// 按指定参数字符串，获取url参数
function getUrlParamByUrl(urlParamStr, strParame) {
    var args = new Object;
    var arr = [];
    var pairs = urlParamStr.substring(1).split("&");
    for (var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf("="); -
        1 != pos && (argname = pairs[i].substring(0, pos),
            value = pairs[i].substring(pos + 1),
            value = decodeURIComponent(value),
            args[argname] = value,
            strParame == argname && value && value.indexOf("undefined") < 0 && arr.push(value))
    }
    return 1 < arr.length ? arr : strParame ? args[strParame] : args
};